//package com.ruoyi.web.controller.redismq.config;
//import java.util.Arrays;
//import java.util.Collection;
//import java.util.Collections;
//import java.util.HashMap;
//import java.util.HashSet;
//import java.util.List;
//import java.util.Map;
//import java.util.concurrent.CountDownLatch;
//
//import com.ruoyi.web.controller.redismq.Receiver;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.boot.autoconfigure.AutoConfigureAfter;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//import org.springframework.data.redis.connection.MessageListener;
//import org.springframework.data.redis.connection.RedisConnectionFactory;
//import org.springframework.data.redis.connection.RedisPassword;
//import org.springframework.data.redis.connection.RedisStandaloneConfiguration;
//import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
//import org.springframework.data.redis.core.StringRedisTemplate;
//import org.springframework.data.redis.listener.PatternTopic;
//import org.springframework.data.redis.listener.RedisMessageListenerContainer;
//import org.springframework.data.redis.listener.Topic;
//import org.springframework.data.redis.listener.adapter.MessageListenerAdapter;
//
//@Configuration
//@AutoConfigureAfter({Receiver.class})
//public class ReceiverConfig {
//    //向容器放入接收对象
//    @Bean
//    public Receiver receiver(@Autowired CountDownLatch latch) {
//        return new Receiver(latch);
//    }
//    //提供给接收对象实体
//    @Bean
//    public CountDownLatch countDownLatch() {
//        return new CountDownLatch(1);
//    }
//    //redis
//    @Bean
//    public StringRedisTemplate stringRedisTemplate(@Autowired RedisConnectionFactory connectionFactory) {
//        return new StringRedisTemplate(connectionFactory);
//    }
//    //redis连接工厂里面参数可以放入到application.properties内通过@value注解引入
////    @Bean
////    public RedisConnectionFactory redisConnectionFactory() {
////        RedisStandaloneConfiguration configuration = new RedisStandaloneConfiguration("192.168.1.22", 32768);
////        configuration.setDatabase(0);
////        RedisPassword password = RedisPassword.of("123456");
////        configuration.setPassword(password);
////        LettuceConnectionFactory factory = new LettuceConnectionFactory(configuration);
////        return factory;
////    }
//    //redis消息监听容器
//    @Bean
//    public RedisMessageListenerContainer getRedisMessageListenerContainer(RedisConnectionFactory redisConnectionFactory, MessageListenerAdapter messageListenerAdapter){
//        RedisMessageListenerContainer redisMessageListenerContainer = new RedisMessageListenerContainer();
//
//        redisMessageListenerContainer.setConnectionFactory(redisConnectionFactory);
//        //new PattenrnTopic跟消息发布者的要一致; 例如消息发布者为stringRedisTemplate.convertAndSend("notify", message);则对应以下
//        redisMessageListenerContainer.addMessageListener(messageListenerAdapter, new PatternTopic("notify"));
//
//        return redisMessageListenerContainer;
//    }
//    /**
//     * 注入消息监听适配器
//     */
//    @Bean
//    public MessageListenerAdapter getMessageListenerAdapter(Receiver receiver){
//        return new MessageListenerAdapter(receiver, "receiveMessage");
//    }
//
//}
//
